﻿<%@ WebHandler Language="C#" Class="HandlerNews" %>

using System;
using System.Web;
using NOAH.CMS.Repository;
using System.Collections.Generic;
using Ext.Net;

public class HandlerNews : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/json";
        int start = 0;
        int limit = 15;
        
        
        int newsCategoryId = 0;
        
        string title = "";

        if (context.Request["filter"] != null)
        {
            title = context.Request["filter"];
        }

        if (context.Request["start"] != null)
        {
            start = Convert.ToInt32(context.Request["start"]);
        }
        if (context.Request["limit"] != null)
        {
            limit = Convert.ToInt32(context.Request["limit"]);
        }
        if (context.Request["newsCatetoryId"] != null)
        {
            newsCategoryId = Convert.ToInt32(context.Request["newsCatetoryId"]);
        }

        int count = 0;

        NewsArticleRepository repository = new NewsArticleRepository();
        List<NewsArticle> news = new List<NewsArticle>();
        news = repository.Filter(title, newsCategoryId, start, limit, out count);
        context.Response.Write(string.Format("{{total:{1},'data':{0}}}", JSON.Serialize(news), count));
     


    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}